package org.example.demo.config;

import org.example.demo.ResponseHttps.ResponseData;
import org.example.demo.SQL.Dao.UserDao;
import org.example.demo.SQL.Models.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/exception")
public class ExceptionController {
    @GetMapping("/test")
    public ResponseData test(){
        int[] arr = {1,2,3};
        arr = null;
        // 发生空指针异常
        System.out.println(arr[0]);
        Map<Integer, User> users = UserDao.findAllUsers();
        return new ResponseData("200",null,true,users);
    }


    @GetMapping("/test2")
    public ResponseData test2(){
        int[] arr = {1,2,3};
        // 发生空指针异常
        System.out.println(arr[3]);
        Map<Integer, User> users = UserDao.findAllUsers();
        return new ResponseData("200",null,true,users);
    }


    @GetMapping("/test3")
    public ResponseData test3(){
        int[] arr = {1,2,3};
        // 发生算法异常
        int i = 0/1;
        Map<Integer, User> users = UserDao.findAllUsers();
        return new ResponseData("200",null,true,users);
    }
}
